package com.zjs.express.service.impl;


import com.zjs.express.bean.Admin;
import com.zjs.express.common.ResultModel;
import com.zjs.express.dao.AdminDao;
import com.zjs.express.dao.impl.AdminDaoImpl;
import com.zjs.express.service.AdminService;

import java.util.Date;

public class AdminServiceImpl implements AdminService {

    private AdminDao adminDao = new AdminDaoImpl();

    /**
     * 登录
     *
     * @param username
     * @param password
     * @return 登录人信息
     */
    @Override
    public ResultModel login(String username, String password, String ip) {
        //通过用户名查询
        Admin admin = adminDao.listByUsername(username);
        //如果可以查询到用户信息，并且密码是对的，登录成功
        if (admin != null && password.equals(admin.getPassword())) {
            //更新登录时间和ip
            adminDao.updateLoginTimeById(admin.getId(), new Date(), ip);
            return ResultModel.success(admin);
        }
        return ResultModel.failure("登录失败！");
    }
}
